<!DOCTYPE html>
<html>

<head>
    <title>游记列表</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/plugins/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/plugins/jquery/jquery.min.js"></script>
    <script src="/js/plugins/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/travel.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css">
    <script src="/js/plugins/dialog2/dialog.js"></script>
</head>

<body>
    <script>
        $(function () {
            //当前页input框
            var currentPage = $("#currentPage");
            //游记总页数
            var pages =1;
            //用于存储游记列表的数据
            var travelDate = [];

            //分页查询的方法
            function query() {
                //当前页的值
                var currentPageValue = currentPage.val();
                //每页显示数量
                var pageSize = $("#pageSize").val();

                //获取所有游记的分页数据
                $.get('/travels', {
                    currentPage: currentPageValue,
                    pageSize: pageSize
                }, function (data) {
                    //往数组容器中存数据(把第二个数组的内容合并到第一个数组中)
                    $.merge(travelDate, data.list);

                    //渲染数据
                    $("#allTravels").renderValues({list: travelDate});
                    //当前页加一(确保获取到第二页数据后currentPage再加一)
                    currentPage.val(parseInt(currentPageValue) + 1);
                    //设置总页数的值
                    pages = data.pages;
                    //给a链接绑定事件 (渲染完后才可以绑定)
                    $("#allTravels a[data-url]").click(function () {
                        var url = $(this).data("url");
                        var id=$(this).data("id");
                        window.location.href=url+id;
                    })
                })


            }

            //默认查询第一页数据
            query();

            //滚动事件
            $(window).scroll(function () {
                //document(html)卷上去的高度+窗口的高度>+document(html)的整个高度
                if ($(document).scrollTop() + $(window).height() >= $(document).height()) {
                    //当前页的值
                    var currentPageValue = currentPage.val();
                    //判断currentPageValue当前页是否大于pages总页数
                    if (currentPageValue <= pages) {
                        query();

                    } else {
                        //提示用户已经到底了

                        $(document).dialog({
                            type: 'notice',
                            infoText: '已经到底了',
                            autoClose: 1000
                        });

                    }
                }
            })


            //获取每月推荐
            $.get('/travels/commends',{type:2,pageSize:5},function (data) {
                $("#travelsCommends").renderValues(data);
                //设置第一个item添加active类 first选择器取第一个
                $(".carousel-item:first").addClass("active");

                //给a链接绑定事件(渲染完后才可以绑定)
                $("#travelsCommends a[data-url]").click(function () {
                    var url=$(this).data("url");
                    var id=$(this).data("tid");//要和渲染的id同名 data-tid
                    window.location.href=url+id;
                })


            })


        })


    </script>


<div class="search-head">
    <div class="row nav-search">
        <div class="col-2">
            <a href="index.html">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>
        <div class="col-10">
            <div class="input-group-sm search">
                <input class="form-control searchBtn" placeholder="搜游记">
            </div>
        </div>
    </div>
</div>

    <input type="hidden" name="currentPage" id="currentPage" value="1">
    <input type="hidden" name="pageSize" id="pageSize" value="3">
<div class="container">

    <h6>每月冠军游记</h6>
    <div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
        <div id="travelsCommends" class="carousel-inner">
            <div render-loop="list">
                <div class="carousel-item ">
                    <div class="border commend">
                        <a href="javascript:;" data-url="travelContent.html?id=" render-attr="data-tid=list.travel_id">

                            <img render-src="list.coverUrl" width="100%" height="200px">
                             <h1 render-html="list.title"> </h1>
                            <small render-html="list.subTitle"></small>
                        </a>
                    </div>
                </div>
            </div>
        </div>

        <a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev">
            <span class="carousel-control-prev-icon" aria-hidden="true"></span>
            <span class="sr-only"></span>
        </a>
        <a class="carousel-control-next" href="#carouselExampleControls" role="button" data-slide="next">
            <span class="carousel-control-next-icon" aria-hidden="true"></span>
            <span class="sr-only"></span>
        </a>
    </div>
</div>

<div class="container">
    <h6>全部游记</h6>
    <div id="allTravels" >
     <div render-loop="list">
        <div class="row detail">
            <div class="col">
                    <a href="javascript:;"
                       data-url="/travelContent.html?id=" render-attr="data-id=list.id">
                    <h4 render-html="list.title"> </h4>
                </a>
                <p>
                    <a href="userProfiles.html" >
                        <img class="rounded-circle head-img" render-src="list.author.headImgUrl">
                        <span render-html="list.author.nickName"></span> </a> 在
                    <span class="addr" render-html="list.place.name"></span>

                </p>
                <p>
                    <i class="fa fa-eye fa-fw"></i>
                    <span>0</span>
                    <i class="fa fa-commenting fa-fw"></i>
                    <span>0</span>
                </p>
            </div>
            <div class="col bigimg">
                <a href="javascript:;"
                   data-url="/travelContent.html?id=" render-attr="data-id=list.id" >
                    <img render-src="list.coverUrl">
                </a>
            </div>
        </div>
     </div>
    </div>
</div>



</body>

</html>